//
//  LJAccount.h
//  LJClientKit
//
//  Created by che on 12/7/09.
//  Copyright 2009 AntonChebotaev. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "LJServer.h"
#import "LJJournal.h"
#import "LJFriend.h"
#import "LJFriendsGroup.h"
#import "LJUserpic.h"
#import "LJTag.h"
#import "NSStringAddition.h"

@class LJServer, LJUserpic, LJJournal;

#pragma mark Exceptions
FOUNDATION_EXPORT NSString* const LJAccountBadInitException;

#pragma mark Notifications
FOUNDATION_EXPORT NSString* const LJAccountWillUpdateNotification;
FOUNDATION_EXPORT NSString* const LJAccountDidUpdateNotification;

FOUNDATION_EXPORT NSString* const LJAccountWillUpdateUserpicsNotification;
FOUNDATION_EXPORT NSString* const LJAccountDidUpdateUserpicsNotification;

FOUNDATION_EXPORT NSString* const LJAccountWillUpdateTagsNotification;
FOUNDATION_EXPORT NSString* const LJAccountDidUpdateTagsNotification;

FOUNDATION_EXPORT NSString* const LJAccountWillUpdateFriendsNotification;
FOUNDATION_EXPORT NSString* const LJAccountDidUpdateFriendsNotification;

/*!
    @class
	@abstract    Represents Livejournal account
    @discussion  Root class for communication with Lijejournal API
*/
@interface LJAccount : NSObject <NSCoding> {
	LJServer* server;
	NSString* username;

	NSMutableSet* journals;  
	NSMutableSet* friends;
	NSMutableSet* friendGroups;
	NSMutableSet* userpics;
	LJUserpic* defaultUserpic;
	LJJournal* defaultJournal;
	
	BOOL updating;
}

@property (readonly) LJServer* server;
@property (readonly) NSString* username;
@property (readonly) NSArray* journals;
@property (readonly) NSSet* friends;
@property (readonly) NSSet* friendGroups;
@property (readonly) NSSet* userpics;
@property (readonly) LJUserpic* defaultUserpic;
@property (readonly) LJJournal* defaultJournal;
@property (readonly) BOOL isUpdating;

/*!
    @function
    @abstract   Generates menu with account's journals
    @discussion Creates new menu and fills it with account's journals items. Each item will have proper icon (which are passed through images dictionary).
				For each NSMenuItem representedObject is a reference to corresponding LJJournal
    @param      images NSDictionary with keys "user" and "community"
    @result     NSMenu with images
*/
- (NSMenu*)journalsMenuWithImages:(NSDictionary*)images;

/*!
    @function
    @abstract   Generates menu with account sepific security categories
    @discussion Adds security groups to default security menu generated by defaultSecurityMenuWithImages:
    @param      images NSDictionary with keys "friends", "private" and "custom"
    @result     NSMenu with images
*/
- (NSMenu*)securityMenuWithImages:(NSDictionary*)images;


+ (NSMenu*)defaultSecurityMenuWithImages:(NSDictionary*)images;
- (NSMenu*)userpicsMenu;

- (id)initWithServerURL:(NSURL*)serverURL username:(NSString*)newUsername;
- (id)initWithUsername:(NSString*)newUsername;

// Synchronic updaters
- (NSString *)updateFromServer:(NSString *)password;
- (void)updateFriends:(NSString *)password;
- (void)updateTags:(NSString *)password;
- (void)reloadUserpicsImages;

// NSOperations for asynchronic use
- (NSOperation*)updateFromServerOperation:(NSString *)password;
- (NSOperation*)updateFriendsOperation:(NSString *)password;
- (NSOperation*)updateTagsOperation:(NSString *)password;
- (NSOperation*)reloadUserpicsImagesOperation;


@end